<?php
namespace app\index\controller;

use app\common\JwtToken;
use think\Controller;
use app\index\service\DetectionService;
class Detection extends Controller
{
    private $detectionService;
    private $userId;
    /**
     * 依赖注入 Service
     *
     * @param DetectionService $detectionService
     * @author zws
     */
    public function __construct(DetectionService $detectionService)
    {
        parent::__construct();
        $this->detectionService = $detectionService;
        // 获取用户id
        $token = $this->request->param('token');
        $this->userId = JwtToken::getTokenUid($token);
    }

    /**
     * 上传检测数据
     * @return \think\response\Json
     * @author zws
     */
    public function uploadData()
    {
//        $xml = file_get_contents('php://input');
        $input = $this->request->input;
        $input['user_id'] = $this->userId;
        $result = $this->detectionService->uploadData($input);
        return app_response(200, []);
    }

    /**
     * 获取检测数据
     * @return \think\response\Json
     * @author zws
     */
    public function detectionData()
    {
        $input = $this->request->input;
        $input['userId'] = $this->userId;
        $result = $this->detectionService->detectionData($input);
        return app_response(200, $result);
    }
}